{extend name="public/base" /}

{block name="title"}<title>{$Think.lang.list}</title>{/block}

{block name="pjax_container"}
<div class="hry-content-wrapper">
    <section class="content-header">
        <ol class="breadcrumb">
            <li>财务管理</li>
            <li class="active">会员对账</li>
        </ol>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="hry-form-wrapper">
                    <div class="box-header with-border" style="height:55px;">
                        <div class="box-tools" style="top:10px;">
                            <form class="form-inline" id="project—form" action="{:url('Money/memberList')}" method="GET"
                                  pjax-search="">
                                <input type='hidden' value='{$user.id}' name='id'>
                                <div class="form-group">
                                    <label for="name">姓名</label>
                                    <input type="text" name="name" id="name" class="form-control" value="{$name}"
                                           placeholder="按姓名搜索"/>
                                </div>
                                <div class="form-group">
                                    <label for="phone" class="hry-require">手机号码</label>
                                    <input type="text" name="phone" id="phone" class="form-control" value="{$phone}"
                                           placeholder="按手机号码"/>
                                </div>
                                <div class="form-group">
                                    <button type="submit" class="btn btn-primary sreachs" onClick="return toVailds()">
                                        搜索
                                    </button>
                                    <button type="button" id="dwonload" class="btn btn-primary sreachs">下载</button>
                                    <button type="button" class="btn btn-primary" onclick="resetForm()">重置</button>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="box-body table-responsive">
                        {if condition=" $dataList.same eq 'NO'"}
                        <div class="member-label"><span>您搜索的手机号与姓名不符</span></div>
                        <div class="member-Info">会员 <span>{$user.username}（{$user.mobile}）</span>的账户情况</div>
                        {elseif condition="$dataList.same eq 'YES'"/}
                        <div class="member-Info">会员 <span>{$user.username}（{$user.mobile}）</span>的账户情况</div>
                        {elseif condition="$dataList.same eq 'NULL'"/}
                        <div class="member-label"><span>您所搜索的手机号不存在</span></div>
                        {else /}
                        <div class="member-label"><span>请搜索你想查看的会员信息</span></div>
                        {/if}
                        <table class="table table-bordered table-hover table-sort">
                            <tr>
                                <th>对账类型</th>
                                <th>总金额（元）</th>
                                <th>操作</th>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">充值金额</td>
                                <td style="vertical-align:middle;color: red">{$dataList.recharge}</td>
                                <td style="vertical-align:middle">
                                    {if condition="$dataList.same eq 'YES'"}
                                    <a class="btn-text btn-primary btn-xs"
                                       href="{:url('Money/memberDetails',['id'=>$user.id])}">查看明细</a>
                                    {else /}
                                    <a class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">查看明细</a>
                                    {/if}
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">认投金额</td>
                                <td style="vertical-align:middle;color: red">{$dataList.recruit}</td>
                                <td style="vertical-align:middle">
                                    {if condition="$dataList.same eq 'YES'"}
                                    <a class="btn-text btn-primary btn-xs"
                                       href="{:url('Money/moneyRecruit',['id'=>$user.id])}">查看明细</a>
                                    {else /}
                                    <a class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">查看明细</a>
                                    {/if}
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">提现金额</td>
                                <td style="vertical-align:middle;color: red">{$dataList.withdraw}</td>
                                <td style="vertical-align:middle">
                                    {if condition="$dataList.same eq 'YES'"}
                                    <a class="btn-text btn-primary btn-xs"
                                       href="{:url('Money/moneyReflect',['id'=>$user.id])}">查看明细</a>
                                    {else /}
                                    <a class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">查看明细</a>
                                    {/if}
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">推广金额</td>
                                <td style="vertical-align:middle;color: red">{$dataList.promotion}</td>
                                <td style="vertical-align:middle">
                                    {if condition="$dataList.same eq 'YES'"}
                                    <a class="btn-text btn-primary btn-xs"
                                       href="{:url('Money/moneyPromotion',['id'=>$user.id])}">查看明细</a>
                                    {else /}
                                    <a class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">查看明细</a>
                                    {/if}
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">手续费</td>
                                <td style="vertical-align:middle;color: red">{$dataList.fee}</td>
                                <td style="vertical-align:middle">
                                    {if condition="$dataList.same eq 'YES'"}
                                    <a class="btn-text btn-primary btn-xs"
                                       href="{:url('Money/moneyFee',['id'=>$user.id])}">查看明细</a>
                                    {else /}
                                    <a class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">查看明细</a>
                                    {/if}
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">分账金额</td>
                                <td style="vertical-align:middle;color: red">{$dataList.subaccount}</td>
                                <td style="vertical-align:middle">
                                    {if condition="$dataList.same eq 'YES'"}
                                    <a class="btn-text btn-primary btn-xs"
                                       href="{:url('Money/moneySubAccount',['id'=>$user.id])}">查看明细</a>
                                    <button type="button" class="btn-text btn-primary btn-xs" data-toggle="modal"
                                            data-target="#extract">结算
                                    </button>
                                    {else /}
                                    <a class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">查看明细</a>
                                    <a type="button" class="btn-text btn-xs" style="color:gray;cursor: no-drop"
                                       onclick="return false">结算
                                    </a>
                                    {/if}
                                    
                                </td>
                            </tr>
                            <tr>
                                <td style="vertical-align:middle">实时余额</td>
                                <td style="vertical-align:middle;color: red">{$dataList.balance}</td>
                                <td style="vertical-align:middle"></td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>
<!--提取弹出框-->
<div class="modal fade" id="extract" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <input type='hidden' value='{$user.id}' name='user_id' id = 'user_id'>
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">分账金额结算</h4>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    <label for="checkMoney" class="control-label">结算金额</label>
                    <input type="text" class="form-control money" name="checkMoney" id="checkMoney">
                </div>
                <div class="form-group">
                    <label for="checkProject" class="control-label">所属项目</label>
                    <select type="text" class="form-control project" name="checkProject" id="checkProject">
                        {volist name="project" id="vo"}
                        <option value="{$vo.id}" >{$vo.project_name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="form-group">
                    <label for="checkPassword" class="control-label">密码:</label>
                    <input type="password" class="form-control password" name="checkPassword" id="checkPassword">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="fenzhang">确认</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<style>
    .member-label {
        text-align: center;
        margin: 20px 0;
        color: red;
    }

    .member-Info {
        text-align: center;
        margin: 20px 0;
    }

    .member-Info span {
        color: orange;
    }
</style>
<script type="text/javascript">
    $(function () {
        window.localStorage.setItem('memberUrl', window.location.href)
        $('#dwonload').click(function () {
            var url = "{:url('Money/memberList')}";
            var name = $("select[name='name']").val();
            var phone = $("input[name='phone']").val();
            var id = $("input[name='id']").val();
            location.href = url + "?name=" + name + "&phone=" + phone + "&id=" + id + "&down=1";
        })
    })

    function toVailds() {
        let id = $('#phone').val()
        var idreg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
        let validate = false
        if (id === '') {
            $.amaran({'message': '请输入手机号!'});
            validate = false
        } else if (!idreg.test(id)) {
            $.amaran({'message': '请输入正确的手机号!'});
            validate = false
        } else {
            validate = true
        }
        return validate
    }
    function resetForm() {
        $('input[name="phone"]').val('')
        $('input[name="name"]').val('')
        let currentUrl = window.location.href.split('?')[0]
        window.location = currentUrl
        // $('#project—form').submit()
    }

    $(function () {
        window.localStorage.setItem('companyUrl', window.location.href)
        $('#extract').on('hide.bs.modal', function (e) {
            $('#checkMoney').val('')
            $('#checkPassword').val('')
            // do something...
        })
        $('#fenzhang').on('click', function () {
            let money = $('#checkMoney').val()
            let project = $('#checkProject').val()
            let checkPassword = $('#checkPassword').val()
            let user_id = $('#user_id').val()
            var isNum = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
            if (!isNum.test(money)) {
                $.amaran({'message': '请输入最多只有两位小数且大于0的金额'});
                return false;
            }
            if(!project){
                $.amaran({'message': '请选择项目'});
                return false;
            }
            if(!checkPassword){
                $.amaran({'message': '请输入密码'});
                return false;
            }
            var formurl = "{:url('Money/memberSettlement')}";
            $.ajax({
                url: formurl,
                type: "POST",
                dataType: "JSON",
                data: {user_id:user_id, money: money, project:project, password: checkPassword},
                success: function (msg) {
                    $.amaran({'message': msg.info.info});
                    console.log(msg)
                    if (msg.info.status == 1) {
                        setTimeout(function () {
                            window.location.reload();
                        }, 500);
                    }
                },
                error: function (res) {
                    $.amaran({'error': res});
                }
            })
        })
        {if condition=" $rest_login == 1 "}
        restlogin('{$rest_login_info}');   //登录超时
        {/if}
    })
</script>
{/block}